home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / hd-install / thor25_arexx.lha / OptConf.thor < prev    next >
Text File  |  1997-04-29  |  14KB  |  473 lines

  1. /* $VER: OptConf V1.10 (27.04.97) Shaun Downend.
  2.  *          <shaund@amiganut.demon.co.uk>
  3.  *         Optimise a conference in a BBS.
  4.  *
  5.  */
  6.  
  7. /* Optional configuration items */
  8.  
  9. repackxpk = 1   /* during optimisation XPK packed conferences are unpacked.
  10.                  * set this to 1 to repack, or 0 to not repack.
  11.                  */
  12.  
  13. /* End configuration */
  14.  
  15. scriptver = subword(sourceline(1), 4,1)
  16. scriptinfo = 'OptConf.thor 'scriptver' © Shaun Downend.'
  17.  
  18. /*!~ "Bit numbers for message flags" */
  19.  
  20. MDB_READ          =  0   /* Message is read. */
  21. MDB_REPLIED       =  1   /* Message is replied. */
  22. MDB_PRIVATE       =  2   /* Message is private. */
  23. MDB_TO_USER       =  3   /* Message is to the user. */
  24. MDB_FROM_USER     =  4   /* Message is from the user. */
  25. MDB_DELETED       =  5   /* Message is deleted. */
  26. MDB_UNRECOVERABLE =  6   /* Message is can not be undeleted. */
  27. MDB_KEEP          =  7   /* Keep message. Message will not be deleted during conference packing. */
  28. MDB_TO_ALL        =  8   /* Message is to all. (has no reciever) */
  29. MDB_XPK_TEXT      =  9   /* Message text is Xpk'ed. (Private flag) */
  30. MDB_MARKED        = 10   /* Message is marked.  */
  31. MDB_URGENT        = 11   /* Message is urgent.  */
  32. MDB_IMPORTANT     = 12   /* Message is important. */
  33. MDB_SUPERMARKED   = 13   /* Message will not be unmarked as long as this flag is set. */
  34.  
  35. CDF_NOT_ON_BBS   = '00008000'x  /* This conference is not on the bbs. */
  36. CDB_NO_XPK_METHOD       = 13    /* Don't use any xpk method. */
  37.  
  38. BDB_NO_XPK_METHOD      = 4   /* Don't use any xpk method. */
  39. GCB_NO_XPK_METHOD      = 3   /* Don't use any xpk method. */
  40.  
  41. /*~!*/
  42.  
  43. options results
  44. options failat 31
  45.  
  46. signal on syntax
  47. signal on halt
  48. signal on break_c
  49. signal on failure
  50.  
  51. /*!~ "Open Thor and BBSREAD ARexx ports" */
  52.  
  53. p=' '||address()||' '||show('P',,)
  54. if pos(' THOR.',p)>0 then
  55. thorport=word(substr(p,pos(' THOR.',p)+1),1)
  56. else
  57. do
  58.     say ('Thor has to be running to use this script!')
  59.     exit(0)
  60. end
  61.  
  62. if ~show('p', 'BBSREAD') then
  63. do
  64.     address command
  65.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  66.     'WaitForPort BBSREAD'
  67.     if rc ~= 0 then call errmsg('Couldn''t open BBSRead''s ARexx port.')
  68. end
  69.  
  70. address(thorport)
  71. 'VERSION STEM 'version
  72.  
  73. fullver = subword(version.THOR, 1, 1)
  74. version.thorver = substr(fullver, 1, index(fullver, '.') - 1)
  75. version.thorrev = compress(substr(fullver, index(fullver, '.') + 1), 'ß')
  76.  
  77. thorversion = version.thorver || '.' || version.thorrev
  78.  
  79. if thorversion < 2.5 then call errmsg('You need at least Thor 2.5 to run this script!')
  80.  
  81. /*~!*/
  82.  
  83. /*!~ "Get list of conference(s) to optimise" */
  84.  
  85. address(thorport)
  86.  
  87. 'currentsystem' CURRENT
  88. if(rc = 1) then call errmsg('CURRENTSYSTEM failed: No current system')
  89. if(rc = 30) then call errmsg('CURRENTSYSTEM failed: 'THOR.LASTERROR)
  90.  
  91. address BBSREAD 'getconflist bbsname "'CURRENT.BBSNAME'" stem' CONFLIST
  92. if(rc = 5) then call errmsg('GETCONFLIST failed: BBS not found')
  93. if(rc ~= 0) then call errmsg('GETCONFLIST failed: 'BBSREAD.LASTERROR)
  94.  
  95. 'requestlist instem' CONFLIST 'outstem' SELECTED 'multiselect dragselect title "Select conference(s) to optimise:"'
  96. if(rc = 5) then exit
  97. if(rc ~= 0) then call errmsg('REQUESTLIST failed: 'THOR.LASTERROR)
  98.  
  99. 'lockgui'
  100.  
  101. address(BBSREAD)
  102.  
  103. drop CONFDATA.
  104. drop BBSDATA.
  105. drop GLOBDATA.
  106.  
  107. /* Get System and Global XPK settings */
  108.  
  109. 'getbbsdata bbsname "'CURRENT.BBSNAME'" stem' BBSDATA
  110. if(rc =  5) then call errmsg('GETBBSDATA failed: BBS name not found')
  111. if(rc = 30) then call errmsg('GETBBSDATA failed: 'BBSREAD.LASTERROR)
  112.  
  113. 'getglobaldata stem' GLOBDATA
  114. if(rc = 30) then call errmsg('GETGLOBALDATA failed: 'BBSREAD.LASTERROR)
  115.  
  116. ptotal = 0
  117.  
  118. longest = 0
  119.  
  120. /* Work out information for progress indicator */
  121.  
  122. do i = 1 to SELECTED.COUNT
  123.  
  124.     'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'SELECTED.i'" stem' CONFDATA
  125.     if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  126.     if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  127.  
  128.     /* find the longest conference name to fix width of progress indicator */
  129.     if length(SELECTED.i) > longest then longest = length(SELECTED.i)
  130.  
  131.     /* find out if the conference is xpk packed, if so then this requires another step */
  132.     if CONFDATA.XPKMETHOD ~= '' then xpk = 10000
  133.     else
  134.     do
  135.         if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpk = 0
  136.         else
  137.         do
  138.             if BBSDATA.XPKMETHOD ~= '' then xpk = 10000
  139.             else
  140.             do
  141.                 if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpk = 0
  142.                 else
  143.                 do
  144.                     if GLOBDATA.XPKMETHOD ~= ''  then xpk = 10000
  145.                     else
  146.                     do
  147.                         if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpk = 0
  148.                     end
  149.                 end
  150.             end
  151.         end
  152.     end
  153.  
  154.     /* total of progress indicator is xpk + create conf (10000) + copy msgs (10000)
  155.      * + pack conf (10000) + delete msgs (10000) + delete conf (10000).
  156.      * 10000 is used (a large value) to reduce inaccuracies on division later on.
  157.      */
  158.     ptotal = ptotal + xpk + 60000
  159. end
  160.  
  161. longest = length('Copying messages in ') + longest + length('to ') + longest + length('.temp')
  162.  
  163. /* open and fix progress indicator width */
  164. call oprog(scriptinfo,ptotal,center('...Starting OptConf.thor...Initialising script...',longest,' '))
  165.  
  166. pcurrent = 0
  167.  
  168. 'bufmode copyback'      /* Turn on copyback mode  */
  169.  
  170. /*~!*/
  171.  
  172. /*!~ "Main loop" */
  173. do n = 1 to SELECTED.COUNT
  174.  
  175.     conference = SELECTED.n
  176.  
  177.     tempconf  = conference'.temp'
  178.  
  179.     call getmsginfo(conference) /* get msg numbers for selected conference */
  180.  
  181.     xpkpack = 0
  182.     /* is conference xpk packed? */
  183.  
  184.     if CONFDATA.XPKMETHOD ~= '' then xpkpack = 1
  185.     else
  186.     do
  187.         if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpkpack = 0
  188.         else
  189.         do
  190.             if BBSDATA.XPKMETHOD ~= '' then xpkpack = 1
  191.             else
  192.             do
  193.                 if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpkpack = 0
  194.                 else
  195.                 do
  196.                     if GLOBDATA.XPKMETHOD ~= ''  then xpkpack = 1
  197.                     else
  198.                     do
  199.                         if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpkpack = 0
  200.                     end
  201.                 end
  202.             end
  203.         end
  204.     end
  205.  
  206.     call uprog(window,pcurrent,'Creating temporary conference 'tempconf'...')
  207.  
  208.     pcurrent = pcurrent + 10000
  209.  
  210.     /* create temporary conference */
  211.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" set' c2x(CDF_NOT_ON_BBS)
  212.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  213.  
  214.     call copyconf(conference,tempconf) /* copy msgs from orig conf to temp conf */
  215.  
  216.     /*!~ "Delete messages in original conference" */
  217.     call uprog(window,pcurrent,'Deleting messages in 'conference)
  218.  
  219.     pstart = pcurrent
  220.  
  221.     if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  222.     do
  223.         pinc = 10000 %  (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  224.  
  225.         do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  226.  
  227.             drop OLDMSGDATA.
  228.  
  229.             if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  230.  
  231.             pcurrent = pcurrent + pinc
  232.  
  233.             'readbrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'datastem' OLDMSGDATA
  234.             if(rc ~= 0) then call bbsreaderr
  235.  
  236.             if ~bittst(OLDMSGDATA.FLAGS,MDB_DELETED) then /* is message already deleted? */
  237.             do
  238.                 'updatebrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'setdeleted'
  239.                 if(rc ~= 0) then call bbsreaderr
  240.             end
  241.         end
  242.         pcurrent = pstart + 10000 /* adjust to fix any inaccuracies in previous division :-) */
  243.     end
  244.     else /* conference is empty so skip */
  245.     do
  246.         pinc = pstart + 10000
  247.         call uprog(window,pcurrent)
  248.     end
  249.     /*~!*/
  250.  
  251.     /*!~ "Pack original conference" */
  252.  
  253.     call uprog(window,pcurrent,'Clearing 'conference'...')
  254.  
  255.     pcurrent = pcurrent + 10000
  256.  
  257.     'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  258.     if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  259.     /*~!*/
  260.  
  261.     call getmsginfo(tempconf) /* get msg numbers for temp conf */
  262.  
  263.     call copyconf(tempconf,conference) /* copy msgs from temp conf to orig conf */
  264.  
  265.     /*!~ "Delete temporary conference" */
  266.     call uprog(window,pcurrent,'Deleting 'tempconf'...')
  267.  
  268.     pcurrent = pcurrent + 10000
  269.  
  270.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  271.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  272.  
  273.     /*~!*/
  274.  
  275.     /*!~ "Repack XPK packed conference" */
  276.     if repackxpk = 1 then
  277.     do
  278.         if xpkpack = 1 then
  279.         do  /* If conference was xpk-packed then pack it */
  280.             call uprog(window,pcurrent,'XPK Packing 'conference'...')
  281.  
  282.             pcurrent = pcurrent + 10000
  283.  
  284.             address(BBSREAD)
  285.             'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  286.             if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  287.  
  288.         end
  289.     end
  290.     /*~!*/
  291.  
  292. end
  293.  
  294. call uprog(window,pcurrent,'Complete.')
  295. do i = 1 to 600
  296. end
  297.  
  298. pcurrent = pcurrent + 10000
  299.  
  300. /*!~ "Notify completion, update conf window, cleanup" */
  301. address(thorport)
  302. 'updateconfwindow'
  303. 'unlockgui'
  304. address(bbsread)
  305. 'bufmode endcopyback'
  306. call cprog(window)
  307. address(thorport)
  308. 'requestnotify "OptConf.thor complete!"' '" _OK "'
  309. if(rc = 30) then say THOR.LASTERROR
  310.  
  311. exit
  312. /*~!*/
  313.  
  314. /*~!*/
  315.  
  316. /*!~ "Copy all messages from one conference to another conference " */
  317. copyconf:
  318.  
  319. parse arg fromconf,toconf
  320.  
  321. call uprog(window,pcurrent,'Copying messages in 'fromconf 'to 'toconf)
  322.  
  323. pstart = pcurrent
  324.  
  325. if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  326. do
  327.     pinc = 10000 % (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  328.  
  329.     do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  330.  
  331.         drop MSGTAGS.
  332.         drop MSGDATA.
  333.  
  334.         if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  335.  
  336.         pcurrent = pcurrent + pinc
  337.  
  338.         'readbrmessage "'CURRENT.BBSNAME'"' '"'fromconf'"' i 'headstem' MSGTAGS 'textstem' MSGTAGS 'datastem' MSGDATA
  339.         if(rc ~= 0) then call bbsreaderr
  340.  
  341.         if ~bittst(MSGDATA.FLAGS,MDB_DELETED) | ~bittst(MSGDATA.FLAGS,MDB_UNRECOVERABLE) then
  342.         do
  343.             exargs = ''
  344.             if ~bittst(MSGDATA.FLAGS,MDB_MARKED)   then exargs = exargs || ' DONTMARKMESSAGE'
  345.             if bittst(MSGDATA.FLAGS,MDB_PRIVATE)   then exargs = exargs || ' PRIVATE'
  346.             if bittst(MSGDATA.FLAGS,MDB_READ)      then exargs = exargs || ' READ'
  347.             if bittst(MSGDATA.FLAGS,MDB_URGENT)    then exargs = exargs || ' URGENT'
  348.             if bittst(MSGDATA.FLAGS,MDB_IMPORTANT) then exargs = exargs || ' IMPORTANT'
  349.  
  350.             'writebrmessage "'CURRENT.BBSNAME'"' '"'toconf'" stem' MSGTAGS exargs
  351.             if(rc ~= 0) then call bbsreaderr
  352.  
  353.             msgnr = result
  354.  
  355.             exargs = ''
  356.  
  357.             if bittst(MSGDATA.FLAGS,MDB_KEEP)    then exargs = exargs || ' SETKEEP'
  358.             if bittst(MSGDATA.FLAGS,MDB_SUPERMARKED) then exargs = exargs || ' SETSUPERUNREAD'
  359.             if bittst(MSGDATA.FLAGS,MDB_REPLIED) then exargs = exargs || ' SETREPLIED'
  360.  
  361.             if MSGDATA.HAZELEVEL ~= 0 then exargs = exargs || ' HAZELEVEL ' || MSGDATA.HAZELEVEL
  362.  
  363.             if exargs ~= '' then 'updatebrmessage "'CURRENT.BBSNAME'"' '"'toconf'"' msgnr exargs
  364.             if(rc ~= 0) then call bbsreaderr
  365.  
  366.         end
  367.         /*
  368.         else say 'Message deleted or unrecoverable'
  369.         */
  370.     end
  371.     pcurrent = pstart + 10000 /* adjust for any inaccuracies in previous division :-) */
  372. end
  373. else /* conference is empty so skip it */
  374. do
  375.     pinc = pstart + 10000
  376.     call uprog(window,pcurrent)
  377. end
  378.  
  379. return
  380. /*~!*/
  381.  
  382. /*!~ "Get message numbers for a conference" */
  383. getmsginfo:
  384. parse arg conf
  385.  
  386. drop CONFDATA.
  387.  
  388. 'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'conf'" stem' CONFDATA
  389. if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  390. if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  391.  
  392. return
  393. /*~!*/
  394.  
  395. /*!~ "Progress indication" */
  396.  
  397. /*!~ "Open progress indicator" */
  398. oprog:
  399. parse arg ptitle,ptotal,ptxt
  400. address(thorport)
  401. 'openprogress title "'ptitle'" total' ptotal 'pt "'ptxt'"'
  402. if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
  403. else window = result
  404. return
  405. /*~!*/
  406.  
  407. /*!~ "Update progress indicator" */
  408. uprog:
  409. parse arg pwindow,pcurrent,ptxt
  410. /*
  411. say 'current 'pcurrent
  412. */
  413. if ptxt = '' then ptxt = ''
  414. else ptxt = 'pt ' || '"'ptxt'"'
  415. address(thorport)
  416. 'updateprogress req' pwindow 'current' pcurrent ptxt
  417. if(rc~=0) then signal cleanup
  418. return(0)
  419. /*~!*/
  420.  
  421. /*!~ "Close Progress indicator" */
  422. cprog:
  423. parse arg pwindow
  424. address(thorport)
  425. 'closeprogress req' pwindow
  426. return
  427. /*~!*/
  428.  
  429. /*~!*/
  430.  
  431. /*!~ "Error handling" */
  432. break_c:
  433.  
  434. call errmsg('User break!')
  435.  
  436. error:
  437. halt:
  438. failure:
  439.  
  440. if rc ~= 0 then call errmsg('+++ Line 'sigl' returned 'rc': 'errortext(rc))
  441.  
  442. cleanup:
  443.  
  444. address(bbsread)
  445. 'bufmode endcopyback'
  446. if window ~= 'WINDOW' then call cprog(window)
  447. address(thorport)
  448. 'unlockgui'
  449. exit(0)
  450.  
  451. errmsg:
  452. parse arg msgtxt
  453. address(thorport)
  454. 'requestnotify "'msgtxt'"' '" _OK "'
  455. if(rc = 30) then say THOR.LASTERROR
  456. signal cleanup
  457. return
  458.  
  459. bbsreaderr:
  460. address(bbsread)
  461. 'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  462. if(rc ~= 0) then
  463. do
  464.     address(thorport)
  465.     'requestnotify "CONFIGCONF failed: 'BBSREAD.LASTERROR'\nFailed to delete temporary conference."' '" _OK "'
  466. end
  467. address(thorport)
  468. 'requestnotify "BBSRead Error: 'BBSREAD.LASTERROR'\nThere appears to be a problem with the database.\nPlease repair the database before running this script.\nSystem    : 'CURRENT.BBSNAME'\nConference: 'fromconf'\nMessage no: 'i'."' '" _OK "'
  469. signal cleanup
  470. return
  471. /*~!*/
  472.  
  473.